
/* -----------------
* brief 
* 1. this is code gen by tools 
* 2. array like [a,b,c] after each field, define the ui html tag in view, 
		a for title, 
		b for show or not ,  
		c for element html tag , currently support : check、radio、select、input、textarea、upload
* 3. XXX
*/
//使用方法：在工程root目录下，执行go generate ./modules/tenant/models
//go:generate legogen -type=Tenant -kv=ModuleName=tenant,PrjName=saas_sys_base -dirconf=../../.. ./Tenant.go
package tenant

import (
	"github.com/mjiulee/lego"
)

func init() {
	lego.AddBeanToSynList(new(Tenant))

}

/* table: "tb_tenant"
 * -----------------
*/
type Tenant struct {
	Id        int64  `xorm:"pk" json:",string"`                  // ["id","hide","hidden"]
	IfDel     int `xorm:"default 0"` // ["deleted","hide","hidden"]
	Cdate     string `xorm:"DateTime created"`    // ["create","show","datetime"]
	Udate     string `xorm:"DateTime updated"`    // ["update","show","datetime"]
    // add your custom field here

    Name string `xorm:"char(64)"`    // ["租户名称","show","input"]
    ParentTenantId int64 `xorm:"" json:",string"`    // ["父租户ID","onlyread","input"]
	Depth int `xorm:""`    // ["租户层级","onlyread","input"] //指租户层次结构中的深度，如root tenant深度为0，二级租户深度为1
	TenantType int `xorm:""`    // ["租户类型","onlyread","input"] //有默认租户类型：0， 单店租户类型：1

		RegisterState int `xorm:""`    // ["是否提交了注册资料","onlyread","input"] //是否已提交注册资料: 0未提交资料、1、已提交资料、2通过审核
	IsPayed int `xorm:""`    // ["是否已支付","onlyread","input"] //是否已提交注册费用
	State int `xorm:""` // ["租户状态","onlyread","input"] //
}


type TenantField struct {
    RegisterState string
	IsPayed string
}

var TenantFiled = TenantField{
	RegisterState: "register_state",
	IsPayed: "is_payed",
}

/*
var MetaSlice = make(map[uintptr]string)
var Meta Tenant
func GenerateMeta() map[uintptr]string{

	Meta.Id = 222

	col := lego.GetDBEngine().TableInfo(Meta).Columns()
	t := reflect.TypeOf(Meta)
	v := reflect.ValueOf(Meta)
	for i := 0; i < t.NumField(); i++ {
		for _, valXorm := range col {
			if t.Field(i).Name == valXorm.FieldName {
				offset := t.Field(i).Offset
				offset = offset
				elm := v.Field(i).Interface()
				addr := (&elm)
				addr = addr
				MetaSlice[offset] = valXorm.Name
				break
			}
		}


	}


	return MetaSlice
}
*/
/*
func GetDbFieldName(meta interface{}, filed interface{}) string {
	filedAddress := (uintptr)(unsafe.Pointer(&(Meta.Name)))
	metaAddress := (uintptr)(unsafe.Pointer(&(Meta)))
	metastr := fmt.Sprintf("%p", &meta)

	offset2 := metaAddress - filedAddress
	offset2 = offset2
	//fmt.Println("nameAddress:", nameAddress)
	//metastr = strings.TrimLeft(metastr, "0x")
	//filedstr := fmt.Sprintf("%p", &meta)
	//pmeta, _ := utils.StringToInt64(metastr)
	//pfiledstr, _ := utils.StringToInt64(filedstr)
	pmeta, _ := hex.DecodeString(metastr)
	//offset := pmeta - pfiledstr
	pmeta = pmeta
	offset := unsafe.Offsetof(Meta.Name)
	//var addr uintptr =
	return MetaSlice[offset]
}
*/